import { defineStore } from 'pinia';
import { login } from '@/api/auth';

export const useUserStore = defineStore('user', {
  state: () => ({
    token: null,
    userInfo: null,
  }),
  
  actions: {
    async login(credentials) {
      const response = await login(credentials);
      this.token = response.token;
      this.userInfo = response.user;
      // 存储 token 到 localStorage
      localStorage.setItem('token', response.token);
    },
    
    logout() {
      this.token = null;
      this.userInfo = null;
      localStorage.removeItem('token');
    },
  },
}); 